package com.af.dao.pay.impl;

import java.util.Map;
import java.util.TreeMap;

import org.apache.log4j.Logger;

import com.af.common.CommonUtil;
import com.af.common.GetSequence;
import com.af.common.GlobalVariables;
import com.af.common.Log4jXmlConfig;
import com.af.common.PropertiesManager;
import com.af.common.SignUtil;
import com.af.dao.pay.IPayToApi;
import com.af.dao.pay.PayEntity;

public class PayToApi implements IPayToApi {
	
	Logger LOG = Log4jXmlConfig.getInstance().returnLogger(PayToApi.class);
	
	@Override
	public String YSQCX(PayEntity order) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new TreeMap<String, Object>();
		
		
		map.put("service_id", GlobalVariables.YSQCX);
		
		//发起方机构编码
		map.put("req_org_cd", PropertiesManager.getInstance().returnValue("req_org_cd"));
		
		//发起时间
		map.put("req_trans_tm", CommonUtil.returnDateFormat("yyyyMMddHHmmss"));
		
		//订单号
		map.put("req_trans_seq", GetSequence.returnSeqNum());
		
		map.put("order_id", order.getOrderid());
		
		//卖家ID
		map.put("seller_id", "12345");
		
		//是否有子订单
		map.put("sub_order_flag", order.getSub_order_flag());
		
		map.put("sub_order_num", order.getSub_order_num());
		
		map.put("sub_order_dtl", "");
		
		map.put("sub_order_dtl", CommonUtil.isNotNullOrEmpty(order.getSub_order_dtl())?order.getSub_order_dtl():"");
		
		map.put("order_desc", CommonUtil.isNotNullOrEmpty(order.getOrder_desc())?order.getOrder_desc():"");
		
		map.put("tot_trans_amt", order.getTot_trans_amt());
		
		map.put("buyer_id", "12345678");
		
		map.put("valid_date", order.getValid_date());
		
		map.put("notify_url", order.getNotify_url());
		
		map.put("return_url", "");
		
		map.put("sign", SignUtil.sign(map,PropertiesManager.getInstance().returnValue("AliKey")));
		
		map.put("sign_type", "MD5");
		
		return new WebSocket().returnWebResponse(map);
	}

	@Override
	public String YSQWC(PayEntity order) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new TreeMap<String, Object>();
		
		map.put("service_id", GlobalVariables.YSQWC);
		
		//发起方机构编码
		map.put("req_org_cd", GlobalVariables.REQ_ORG_CD);
		
		//发起时间
		map.put("req_trans_tm", CommonUtil.returnDateFormat("yyyyMMddHHmmss"));
		
		//订单号
		map.put("req_trans_seq", GetSequence.returnSeqNum());
		
		map.put("order_id", order.getOrderid());
		
		map.put("seller_id", "12345");
		
		map.put("sub_order_flag", order.getSub_order_flag());
		
		map.put("sub_order_num", order.getSub_order_num());
		
		map.put("sub_order_dtl", CommonUtil.isNotNullOrEmpty(order.getSub_order_dtl())?order.getSub_order_dtl():"");
		
		map.put("order_desc", CommonUtil.isNotNullOrEmpty(order.getOrder_desc())?order.getOrder_desc():"");
		
		map.put("tot_trans_amt", order.getTot_trans_amt());
		
		map.put("buyer_id", "12345678");
		
		map.put("valid_date", order.getValid_date());
		
		map.put("notify_url", order.getNotify_url());
		
		map.put("return_url", "");
		
		map.put("sign", SignUtil.sign(map,PropertiesManager.getInstance().returnValue("AliKey")));
		
		map.put("sign_type", "MD5");
		
		return new WebSocket().returnWebResponse(map);
		
	}

	/**
	 * 退货，机票预订退票时调用
	 */
	@Override
	public String REFUND(PayEntity order) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new TreeMap<String, Object>();
		
		map.put("service_id", PropertiesManager.getInstance().returnValue("REFUND"));
		
		//发起方机构编码
		map.put("req_org_cd", PropertiesManager.getInstance().returnValue("req_org_cd"));
		
		//发起时间
		map.put("req_trans_tm", CommonUtil.returnDateFormat("yyyyMMddHHmmss"));
		
		//订单号
		map.put("req_trans_seq", GetSequence.returnSeqNum());
		
		map.put("order_id", order.getOrderid());
		
		map.put("seller_id", "12345");
		
		map.put("sub_order_flag", order.getSub_order_flag());
		
		map.put("sub_order_num", order.getSub_order_num());
		
		map.put("sub_order_dtl", CommonUtil.isNotNullOrEmpty(order.getSub_order_dtl())?order.getSub_order_dtl():"");
		
		map.put("order_desc", CommonUtil.isNotNullOrEmpty(order.getOrder_desc())?order.getOrder_desc():"");
		
		map.put("tot_trans_amt", order.getTot_trans_amt());
		
		map.put("buyer_id", "12345678");
		
		map.put("valid_date", order.getValid_date());
		
		map.put("notify_url", order.getNotify_url());
		
		map.put("return_url", "");
		
		map.put("sign", SignUtil.sign(map,PropertiesManager.getInstance().returnValue("AliKey")));
		
		map.put("sign_type", "MD5");
		
		return new WebSocket().returnWebResponse(map);
		
	}

}
